<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ 顺序消息深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            border-bottom: 1px solid #444;
        }
        
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
            color: #d4d4d4;
            font-family: 'Consolas', 'Monaco', monospace;
            line-height: 1.6;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 16px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, #764ba2, transparent);
            margin: 60px 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .mermaid {
            background: white;
            padding: 30px;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .scenario-card {
            background: white;
            border-radius: 16px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .scenario-card:hover {
            border-color: #667eea;
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(102, 126, 234, 0.1);
        }
        
        .badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    RocketMQ 顺序消息
                    <span class="block text-3xl md:text-4xl mt-4 opacity-90">深度技术解析</span>
                </h1>
                <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                    探索分布式消息系统中的顺序性保证机制，从原理到实践的全方位解读
                </p>
                <div class="mt-10 flex justify-center space-x-6">
                    <div class="text-center">
                        <i class="fas fa-layer-group text-3xl mb-2"></i>
                        <p class="text-sm">全局顺序</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-project-diagram text-3xl mb-2"></i>
                        <p class="text-sm">分区顺序</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-shield-alt text-3xl mb-2"></i>
                        <p class="text-sm">可靠保证</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16 max-w-6xl">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>分布式消息系统中，保证消息的顺序性是一个重要且复杂的问题。RocketMQ 提供了两种级别的顺序消息：全局顺序和分区顺序。本文将深入探讨这两种实现方式的原理、性能特点以及实际应用场景。
            </p>
        </section>

        <!-- 全局顺序与分区顺序 -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-12 text-center text-gradient">顺序消息实现原理</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- 全局顺序 -->
                <div class="card-hover bg-white rounded-2xl p-8">
                    <div class="feature-icon">
                        <i class="fas fa-globe"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">全局顺序消息</h3>
                    <p class="text-gray-600 mb-6">
                        对于指定的 Topic，所有消息按照发送的先后顺序进行消费。
                    </p>
                    
                    <h4 class="font-semibold text-lg mb-3 text-purple-600">
                        <i class="fas fa-cogs mr-2"></i>实现原理
                    </h4>
                    <ul class="space-y-3 mb-6">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong>单队列设计：</strong>Topic 下只有一个队列（Queue）
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong>串行处理：</strong>所有消息都进入唯一队列，按 FIFO 方式消费
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong>锁定机制：</strong>Broker 端对队列加锁，确保单一消费者
                            </div>
                        </li>
                    </ul>
                    
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-code mr-2"></i>Java 代码示例
                        </div>
                        <pre><code>// 创建只有一个队列的Topic
admin.createTopic("TopicTest", "globalOrderTopic", 1);</code></pre>
                    </div>
                </div>

                <!-- 分区顺序 -->
                <div class="card-hover bg-white rounded-2xl p-8">
                    <div class="feature-icon">
                        <i class="fas fa-th"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">分区顺序消息</h3>
                    <p class="text-gray-600 mb-6">
                        具有相同分区键的消息按顺序消费，不同分区键的消息可并行处理。
                    </p>
                    
                    <h4 class="font-semibold text-lg mb-3 text-purple-600">
                        <i class="fas fa-cogs mr-2"></i>实现原理
                    </h4>
                    <ul class="space-y-3 mb-6">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong>多队列设计：</strong>Topic 下有多个队列
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong>分区策略：</strong>根据分区键将消息路由到固定队列
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong>队列锁定：</strong>每个队列单独加锁，保证消费顺序
                            </div>
                        </li>
                    </ul>
                    
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-code mr-2"></i>核心源码
                        </div>
                        <pre><code>// 生产者选择队列的策略
public MessageQueue selectOneMessageQueue(
    final TopicPublishInfo tpInfo, 
    final String lastBrokerName) {
    if (this.sendLatencyFaultEnable) {
        // 容错策略
    } else {
        // 默认策略：对分区键取模选择队列
        int index = this.sendWhichQueue.getAndIncrement();
        int pos = Math.abs(index) % 
                  tpInfo.getMessageQueueList().size();
        return tpInfo.getMessageQueueList().get(pos);
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- 架构图 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">消息顺序架构图</h2>
            <div class="mermaid">
                graph TB
                    subgraph "全局顺序"
                        P1[生产者] --> Q1[单一队列]
                        Q1 --> C1[消费者]
                    end
                    
                    subgraph "分区顺序"
                        P2[生产者] --> |订单1| Q2[队列1]
                        P2 --> |订单2| Q3[队列2]
                        P2 --> |订单3| Q4[队列3]
                        Q2 --> C2[消费者1]
                        Q3 --> C3[消费者2]
                        Q4 --> C4[消费者3]
                    end
                    
                    style P1 fill:#667eea,stroke:#fff,color:#fff
                    style P2 fill:#667eea,stroke:#fff,color:#fff
                    style Q1 fill:#764ba2,stroke:#fff,color:#fff
                    style Q2 fill:#764ba2,stroke:#fff,color:#fff
                    style Q3 fill:#764ba2,stroke:#fff,color:#fff
                    style Q4 fill:#764ba2,stroke:#fff,color:#fff
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- 性能与可靠性 -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-12 text-center text-gradient">性能与可靠性保证</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <!-- 性能对比 -->
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-2xl p-8">
                    <h3 class="text-2xl font-bold mb-6 flex items-center">
                        <i class="fas fa-tachometer-alt mr-3 text-purple-600"></i>
                        性能考量
                    </h3>
                    
                    <div class="space-y-6">
                        <div>
                            <h4 class="font-